#!/bin/sh
#
# Run parser tests
#
# Copyright © 2017 Eric Bavier <bavier@member.fsf.org>
# License: GPLv3+
#####

input=tests/lexer/output
output=tests/parser/output
log=test-parser.log
rm -f $log
ret=0

run_test ()
{
    base="$1"
    echo "$base: " >>$log
    tmp=test-parser-$base.tmp
    timeout 5s ./parser < "$input/$base.out" >$tmp 2>/dev/null
    if diff -Nau $output/$base.out $tmp >>$log; then
        printf "$base: PASS\n\n" >>$log
    else
	printf "$base: FAIL\n\n" >>$log
	ret=1
    fi
    rm $tmp
}

run_test assign
run_test flip-flop
run_test choice
run_test big-choice
run_test else
run_test print
run_test expr
run_test test-case-1
run_test test-case-2
run_test test-case-3
run_test test-case-4
run_test count
run_test 100_doors
run_test negative
run_test deep
run_test gcd
run_test factorial
run_test fibonacci
run_test fizzbuzz
run_test 99bottles
run_test primes
run_test mandelbrot

exit $ret
